cmake_minimum_required(VERSION 3.10)
project(sophon-stream)
set(CMAKE_CXX_STANDARD 17)

if (NOT DEFINED TARGET_ARCH)
    set(TARGET_ARCH pcie)
endif()

if (${TARGET_ARCH} STREQUAL "soc")
    if (NOT DEFINED SOPHON_SDK_SOC)
        message(FATAL_ERROR "Please set SOPHON_SDK_SOC for building soc")
    endif()
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/lib)
add_subdirectory(framework)

set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
message("PROJECT_ROOT = ${PROJECT_ROOT}")

function (checkAndAddElement dir)
    if(EXISTS "${PROJECT_ROOT}/${dir}" AND IS_DIRECTORY "${PROJECT_ROOT}/${dir}")
        add_subdirectory(${dir})
    endif()
endfunction()

function (checkAndAddSample dir)
    if(EXISTS "${PROJECT_ROOT}/${dir}" AND IS_DIRECTORY "${PROJECT_ROOT}/${dir}")
        set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_ROOT}/${dir}/build)
        add_subdirectory(${dir})
    endif()
endfunction()

checkAndAddElement(element/algorithm/posec3d)
checkAndAddElement(element/algorithm/fastpose)
checkAndAddElement(element/algorithm/yolox)
checkAndAddElement(element/algorithm/yolov5)
checkAndAddElement(element/algorithm/yolov7)
checkAndAddElement(element/algorithm/bytetrack)
checkAndAddElement(element/algorithm/resnet)
checkAndAddElement(element/algorithm/openpose)
checkAndAddElement(element/algorithm/retinaface)
checkAndAddElement(element/algorithm/lprnet)
checkAndAddElement(element/algorithm/ppocr)
checkAndAddElement(element/algorithm/yolov8)

checkAndAddElement(element/multimedia/decode)
checkAndAddElement(element/multimedia/osd)
checkAndAddElement(element/multimedia/encode)

checkAndAddElement(element/tools/blank)
checkAndAddElement(element/tools/distributor)
checkAndAddElement(element/tools/converger)
checkAndAddElement(element/tools/http_push)
checkAndAddElement(element/tools/faiss)

checkAndAddElement(element/tools/dwa)
checkAndAddElement(element/tools/dpu)
checkAndAddElement(element/tools/blend)
checkAndAddElement(element/tools/ive)
checkAndAddElement(element/tools/stitch)
checkAndAddElement(element/tools/fisheye)
checkAndAddElement(element/tools/resize)
checkAndAddElement(element/tools/filter)
checkAndAddElement(element/tools/qt_display)

checkAndAddElement(3rdparty/freetype2)

checkAndAddSample(samples)
